23 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
24 #define For(i, a, b) for (int i=(a); i<(b); ++i)
25 #define D(x) cout << #x " is " << x << endl
27 const int MAXN
= 1025;
32 void add(int r
, int c
, int what
) {
33 for (r
++; r
<= N
; r
+= r
& -r
) {
34 for (int d
= c
+ 1; d
<= N
; d
+= d
& -d
) {
40 int get(int r
, int c
) {
42 for (r
++; r
> 0; r
-= r
& -r
) {
43 for (int d
= c
+ 1; d
> 0; d
-= d
& -d
) {
50 int sum(int r1
, int c1
, int r2
, int c2
) {
51 return get(r2
, c2
) - get(r1
- 1, c2
) - get(r2
, c1
- 1) + get(r1
- 1, c1
- 1);
54 void set(int r
, int c
, int what
) {
55 int prev
= mat
[r
+1][c
+1];
57 add(r
, c
, what
- prev
);
61 int t
; scanf("%d", &t
);
64 for (int i
= 0; i
<= N
; ++i
) {
65 for (int j
= 0; j
<= N
; ++j
) {
66 tree
[i
][j
] = mat
[i
][j
] = 0;
72 if (!strcmp(buf
, "SET")) {
73 int r
, c
, x
; scanf("%d %d %d", &r
, &c
, &x
);
74 //printf("Set (%d, %d) to %d\n", r, c, x);
76 } else if (!strcmp(buf
, "SUM")) {
77 int r1
, c1
, r2
, c2
; scanf("%d %d %d %d", &r1
, &c1
, &r2
, &c2
);
78 //printf("Sum (%d, %d) to (%d, %d)\n", r1, c1, r2, c2);
79 int ans
= sum(r1
, c1
, r2
, c2
);
82 //printf("Take a break.\n");